package com.dpp.service.impl;

import com.dpp.entity.ActivityRecord;
import com.dpp.mapper.ActivityRecordMapper;
import com.dpp.service.ActivityRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityRecordServiceImpl implements ActivityRecordService {
    @Autowired
    private ActivityRecordMapper activityRecordMapper;
    @Override
    public List<ActivityRecord> selectByOpenid(String openId) {
        return activityRecordMapper.selectByOpenid(openId);
    }

    @Override
    public void insert(Integer activityId, String openId) {
        LocalDateTime now = LocalDateTime.now();
        ActivityRecord activityRecord=ActivityRecord.builder().openId(openId).activityId(activityId).recordStartTime(now).RecordFinished(ActivityRecord.start).build();
        activityRecordMapper.insert(activityRecord);
    }
    @Override
    public void CouponInsert(Integer activityId, String openId) {
        LocalDateTime now = LocalDateTime.now();
        ActivityRecord activityRecord=ActivityRecord.builder().openId(openId).activityId(activityId).recordStartTime(now).RecordFinished(ActivityRecord.CouponStart).build();
        activityRecordMapper.insert(activityRecord);
    }

    @Override
    public void updateEndRecord(Integer activityId, String openId) {
        LocalDateTime now = LocalDateTime.now();
        activityRecordMapper.updateEndRecord(activityId,now,openId);
    }

    @Override
    public ActivityRecord selectByActivityId(String openid, Integer ActivityId) {
        return activityRecordMapper.selectByActivityId(openid,ActivityId);
    }

    @Override
    public List<ActivityRecord> selectByListOpenid(String openId, Integer finished) {
        return activityRecordMapper.selectByListOpenid(openId,finished);
    }
}
